package com.meizi.user.service.controller;

import com.meizi.core.tool.exception.BizException;
import com.meizi.core.tool.api.R;
import com.meizi.user.service.biz.AbstractLogin;
import com.meizi.user.service.biz.Login;
import com.meizi.user.service.bo.AuthLoginBo;
import com.meizi.user.service.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author meizi
 * @email enjoymeizi@gmail.com
 * @date 2020/11/26 14:19
 */
@RestController
@RequestMapping("login")
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping
    public R doLogin(@RequestBody @Validated AuthLoginBo authLoginBo, BindingResult bindingResult) {
        authLoginBo.validData(bindingResult);
        Login login= AbstractLogin.loginMap.get(authLoginBo.getLoginType());
        if(login==null){
            throw new BizException("暂不支持该种登录类型");
        }
        return login.doLogin(authLoginBo);
    }
}
